#!/bin/bash
# Download and statically build Phast, which is required for halPhyloP
# all binaries get copied into cactus/bin

# set this to one to make sure everything gets built statically (necessary for binary release)
STATIC_CHECK=$1

set -beEu -o pipefail
gitrel=85f7ed179dd097a86ba4added22d571785cc3e1d

# works on MacOS and Linux
numcpu=$(getconf _NPROCESSORS_ONLN)

# hal expects phast as a sister directory, so we stick it there
submodulesDir=$(pwd)/submodules
CWD=$(pwd)

set -x

# build clapack
cd ${submodulesDir}
rm -rf clapack
wget -q http://www.netlib.org/clapack/clapack.tgz
tar -xvzf clapack.tgz
mv CLAPACK-3.2.1 clapack
cd clapack
cp make.inc.example make.inc && make -j ${numcpu} f2clib && make -j ${numcpu} blaslib && make -j ${numcpu} lib
export CLAPACKPATH=$(pwd)
cd ..

# build phast
cd ${submodulesDir}
rm -rf phast
git clone https://github.com/CshlSiepelLab/phast.git
cd phast
git checkout ${gitrel}
cd src && make -j ${numcpu}

cd ${CWD}

set +x
